Imports DAOMain
Imports System.Data

Partial Class Accounting_Commision
    Inherits WebPageCommon

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sec As New Secure

        With sec
            .ParentPage = Me
            .AddDataGridColumn(DataGrid, DataGrid.Columns.Count - 3, Secure.ControlTypes.EditType)
            .AddDataGridColumn(DataGrid, DataGrid.Columns.Count - 2, Secure.ControlTypes.DeleteType)

            .SetPageAccess(Session("UserName"))
        End With
    End Sub

    Protected Sub Search_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Search_btn.Click
        Call DoSearch()
    End Sub

    Private Sub DoSearch()
        Dim dao As New VW_COMMISION_PAYABLE_SEARCH_DAO
        Dim vo As New VW_COMMISION_PAYABLE_SEARCH_VO
        Dim cf As New CIMSfunc

        With vo
            If Startdate_txt.Text <> "" Then .POLICY_DUE_DT = cf.ParseSetDate(Startdate_txt.Text)
            If Enddate_txt.Text <> "" Then .POLICY_DUE_DT_TO = cf.ParseSetDate(Enddate_txt.Text)
            .NAME = "%" & Client_txt.Text & "%"
            .PAYMENT_NO = "%" & AR_txt.Text & "%"
            .POLICY_NO = "%" & Policynumber_txt.Text & "%"
            .PRDT_DESC = "%" & Product_txt.Text & "%"
            .PROVIDER_DESC = "%" & Provider_txt.Text & "%"
            .PAYMENT_NO = "%" & AR_txt.Text & "%"
        End With

        With dao
            Dim dt As DataTable = dao.Search(vo, , True)

            results_label.Text = dt.Rows.Count
            ViewState.Add("dt", dt)
            DataGrid.CurrentPageIndex = 0
            DataGrid.DataSource = ViewState("dt")
            DataGrid.DataBind()
        End With

        dao = Nothing
        vo = Nothing
        cf = Nothing

    End Sub

    Protected Sub DataGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid.ItemCommand

        With e.Item
            Select Case LCase(e.CommandName)
                Case "view"
                    Session.Add("mode", "view")
                    Session.Add("Seq_CD", .Cells(0).Text)
                    Session.Add("CID", .Cells(1).Text)
                    Session.Add("CName", .Cells(2).Text)

                    Response.Redirect("~/Accounting/CommisionDetails.aspx")
                Case "edit"
                    Session.Add("Seq_CD", .Cells(0).Text)
                    Session.Add("CID", .Cells(1).Text)
                    Session.Add("CName", .Cells(2).Text)

                    Response.Redirect("~/Accounting/CommisionDetails.aspx")

            End Select
        End With
    End Sub

    Protected Sub DataGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid.ItemDataBound
        Select Case e.Item.ItemType
            Case ListItemType.Item, ListItemType.AlternatingItem
                If e.Item.Cells(12).Text = "&nbsp;" Then
                    Dim Edit_btn As LinkButton = e.Item.FindControl("Edit_btn")
                    If Not IsNothing(Edit_btn) Then Edit_btn.Enabled = False

                    Dim View_btn As LinkButton = e.Item.FindControl("View_btn")
                    If Not IsNothing(View_btn) Then View_btn.Enabled = False
                End If
        End Select
    End Sub

    Protected Sub DataGrid_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid.PageIndexChanged
        DataGrid.CurrentPageIndex = e.NewPageIndex
        DataGrid.DataSource = ViewState("dt")
        DataGrid.DataBind()
    End Sub

End Class
